package com.qf.work20250103;

import java.sql.*;
import java.util.ArrayList;

/**
 * @author zdl
 * @date 2025/1/3
 */
public class Demo1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/mydb1_2?useUnicode=true&characterEncoding=utf8&useSSL=false";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        Statement statement = connection.createStatement();
        //插入
      /*  int i = statement.executeUpdate("insert into tb_user (username,password,phone,create_time,money,sex) values ('user11111','123','13843838438',SYSDATE(),2000.0,1)");
        if (i > 0){
            System.out.println("插入成功!");
        }else {
            System.out.println("插入失败！");
        }*/
        //修改
        /*int i = statement.executeUpdate("update tb_user set money = 199999 where id = 1");
        if (i > 0){
            System.out.println("修改成功!");
        }else {
            System.out.println("修改失败！");
        }*/
        //删除
        /*int i = statement.executeUpdate("delete from tb_user where id = 3");
        if (i > 0){
            System.out.println("删除成功!");
        }else {
            System.out.println("删除失败！");
        }*/
        // 查询
        ResultSet result = statement.executeQuery("select * from tb_user");
        while (result.next()) {
            int id = result.getInt("id");
            String name = result.getString("username");
            String pwd = result.getString("password");
            String phone = result.getString("phone");
            Date create_time = result.getDate("create_time");
            String sex = result.getString("sex");
            double money = result.getDouble("money");
            ArrayList list = new ArrayList();
            list.add(id);
            list.add(name);
            list.add(pwd);
            list.add(phone);
            list.add(create_time);
            list.add(sex);
            list.add(money);
            //System.out.println(id + "-" + name + "-" + pwd + "-" + phone + "-" + sex + "-" + create_time + "-" + money);
            System.out.println(list);
        }
        statement.close();
        connection.close();

    }
}
